package affilication.imp;

import affilication.Affiliation;
import domain.ServiceCharge;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class UnionAffiliation implements Affiliation {
    private double dues;
    private int memberId;
    private Map<Date, ServiceCharge> serviceChargeMap = new HashMap<>();

    public UnionAffiliation(int memberId, double dues) {
        this.memberId = memberId;
        this.dues = dues;
    }


    public double getDues() {
        return dues;
    }

    public void setDues(double dues) {
        this.dues = dues;
    }

    public int getMemberId() {
        return memberId;
    }

    public void setMemberId(int memberId) {
        this.memberId = memberId;
    }

    public void addServiceCharge(ServiceCharge serviceCharge) {
        serviceChargeMap.put(serviceCharge.getDate(), serviceCharge);
    }

    public ServiceCharge getServiceCharge(Date date) {
        return serviceChargeMap.get(date);
    }

    @Override
    public double getDeduction() {
        double sum = 0;
        for(Date date : serviceChargeMap.keySet()) {
            ServiceCharge serviceCharge = serviceChargeMap.get(date);
            sum += serviceCharge.getAmount();
        }
        serviceChargeMap.clear();
        return sum;
    }
}
